<template>
  <view class="history-list">
    <view class="title">历史记录</view>
    <scroll-view 
      scroll-y 
      class="list"
      v-if="history.length"
    >
      <view 
        v-for="(item, index) in history" 
        :key="index"
        class="history-item"
        @click="handleSelect(item)"
      >
        <text class="time">{{ formatDate(item.date) }}</text>
        <text class="shi-chen">时辰：{{ item.shiChen }}</text>
      </view>
    </scroll-view>
    <view v-else class="empty">暂无历史记录</view>
  </view>
</template>

<script>
import { mapState, mapActions } from 'vuex'
import { formatDate } from '@/utils/date'

export default {
  name: 'HistoryList',
  computed: {
    ...mapState('qimen', ['history'])
  },
  created() {
    this.loadHistory()
  },
  methods: {
    ...mapActions('qimen', ['loadHistory', 'updateCurrentTime']),
    formatDate,
    
    handleSelect(item) {
      this.updateCurrentTime(new Date(item.date))
    }
  }
}
</script>

<style lang="scss" scoped>
.history-list {
  padding: 20rpx;
  
  .title {
    font-size: 32rpx;
    font-weight: bold;
    margin-bottom: 20rpx;
  }
  
  .list {
    max-height: 400rpx;
    
    .history-item {
      padding: 20rpx;
      background-color: #f8f8f8;
      margin-bottom: 10rpx;
      border-radius: 8rpx;
      display: flex;
      justify-content: space-between;
      align-items: center;
      
      .time {
        font-size: 28rpx;
      }
      
      .shi-chen {
        font-size: 24rpx;
        color: #666;
      }
    }
  }
  
  .empty {
    text-align: center;
    color: #999;
    padding: 40rpx;
  }
}
</style> 